home *** CD-ROM | disk | FTP | other *** search
- Path: news.minn.net!news
- From: gruch@minn.net (Gerry Ruch)
- Newsgroups: comp.lang.c
- Subject: Re: Array indexing with malloc
- Date: Sun, 21 Apr 1996 17:03:53 GMT
- Organization: Minn Net
- Message-ID: <4ldimv$9ed@cobra.Minn.Net>
- References: <96110.093936F0O@psuvm.psu.edu> <4lan7j$1op@cobra.Minn.Net>
- NNTP-Posting-Host: dialup-217.minn.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- gruch@minn.net wrote:
-
- >A couple of things.
- >First your 64k problem. malloc has a 64k size limit. To allocate a
- >huge array you must use halloc. The compilers I've used (i'm not
- >certain that this is true in all compilers) require huge arrays
- >allocated with halloc larger than 128k to have an elelment size that
- >is a power of 2. Therefore the statement-
-
- >ptr = halloc(1000, 3); // 1000 elements at 3 bytes- total 3000 bytes
-
- >is illegal. But-
-
- >ptr = halloc(750, 4); // 750 elements at 4 bytes- total 3000 bytes
-
- >is legal. That should take care of your size limit problem.
-
- Ok- So that was a pretty shoddy example. 3000 bytes hardly seems to
- add up to 128K. Not sure what I was thinking. A better example would
- have been:
-
- Illegal:
- ptr = halloc(47000, 3); // 47000 elements at 3 bytes- total 141,000
- bytes
-
- Legal:
- ptr = halloc(35250, 4); // 35250 elements at 4 bytes- total 141,000
- bytes
-
- Sorry for the mistake.
-
- ~Gerry.
-
-